#include <iostream>
#include <vector>

using namespace std;

int n, k;

const int N = 20;
int st[N];
vector<int> a;

void dfs()
{
	if (a.size() == k)
	{
		for (auto x : a)
		{
			cout << x << " ";
		}
		cout << endl;
		return;
	}
	
	for (int i = 1; i <= n; i++)
	{
		if (st[i] == true) continue;
		a.push_back(i);
		st[i] = true;
		
		dfs();
		
		a.pop_back();
		st[i] = false;
	} 
}

int main()
{
	cin >> n >> k;
	
	dfs();
	
	return 0;
} 
